package com.aaa.whj.Service.Impl;

import com.aaa.whj.Service.UserService;
import com.aaa.whj.dao.StudentDao;
import com.aaa.whj.dao.UserDao;
import com.aaa.whj.entity.User;
import com.aaa.whj.until.JwtUtil;
import com.aaa.whj.vo.LoginVo;
import com.aaa.whj.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/23  19:42
 */
@Service
public class UserServiceimpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public Result selectUser(LoginVo loginVo) {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("username",loginVo.getUsername());
        wrapper.eq("password",loginVo.getPassword());
        User user = userDao.selectOne(wrapper);
        if (user != null){
            HashMap<String, Object> map = new HashMap<>();
            map.put("name",loginVo.getUsername());
            String token = JwtUtil.createToken(map);
            return  new Result(200,"查询成功",token);
        }
        return  new Result(500,"查询失败",null);
    }
}
